home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-28 | 29.8 KB | 1,090 lines | [TEXT/MPS ] |
- /*
- File: Disptch.cpp
-
- Contains: Implementation of class ODDispatcher
-
- Owned by: Richard Rodseth
-
- Copyright: © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <4> 6/14/96 CSL 1257735: Can't register for idle time
- during idle time
- <3> 6/12/96 eeh 1316602: set modifiers field for
- manufactured events (e.g. mouseMoved)
- <2> 5/01/96 NP 1300091,1282521: Replace badly written bug
- workaround, IntlTSMEvent, with TSMEvent.
- <50> 10/17/95 jpa 1292659: Ignore exceptions sending null
- events to parts
- <49> 10/10/95 DM 1277216: GM:API: Dont return ODPoint from
- GetWindowPoint()
- <48> 10/3/95 TJ Changes done by RefBall Team
- <47> 9/6/95 RR #1282075 ADded ODVolatile
- <46> 8/29/95 RR # 1276401 Respect Mouse Focus
- <45> 8/26/95 TÇ 1274606 FB2: Patching Remarks
- <44> 8/23/95 NP 1264142: Don't Release null object.
- <43> 8/15/95 RR #1222870 Moved NULL handling to end of
- method to allow patching/monitors
- <42> 8/3/95 RR #1257260: Collapse B classes. Remove
- somInit methods. Don't call IsInitialized
- or SubclassResponsibility
- <41> 6/29/95 NP 1263893: Fix TSM support.
- <40> 6/25/95 TÇ 1242642 BB: Turn on ODDebug warning if
- refcount is wrong in
- ODRefCntObjectsomUninit.
- <39> 6/23/95 CC 1256943: MouseRegionIsInvalid: Replaced
- StillDown with Button.
- <38> 6/22/95 NP 1260250: Set up correctly for call to
- CallEventHandler.
- <37> 6/20/95 JP 1251250: ChangedReleaseExtension into
- Release
- <36> 6/15/95 RR #1254828/1255536 Added Redispatch
- <35> 6/8/95 RR #1257260 Collapse base classes. #1214898
- StdTypes.r -> ODTypes.r
- <34> 5/31/95 RR #1251403 Release after AcquirePart
- <33> 5/26/95 RR #1251403: Multithreading naming support
- <32> 5/25/95 jpa Fixed usage of ODDebug. [1253321]
- <31> 5/21/95 NP 1251212: Wrap procs with UPPs.
- <30> 5/17/95 RR #1250135/1250137/1250143 Getters increment
- refcount
- <29> 5/10/95 RR #1239139 MouseEnter etc. over active
- border go to container. Don't send
- until mouse up.
- <28> 5/10/95 RR #1239139 MouseEnter etc. over active
- border go to container. Don't send until mouse up.
- <27> 4/27/95 eeh 1230798: call part::ReleaseExtension
- <26> 4/7/95 RR #1216618 Added SOM_TRY etc.
- <25> 4/4/95 RR # 1211085 Removed fThreadsAvailable,
- #1220104 Use ODObjectsAreEqual, #1228161
- RegisterIdle does not update frequency if
- called twice
- <24> 3/20/95 jpa Cooperative thread support [1167943]. Moved
- bg click handler installation to private
- impl file [1220704].
- <23> 3/10/95 RR # 1187137 Set Cursor to arrow in
- InvalidateFacetUnderMouse
- <22> 2/24/95 jpa Install BG-mouse-down handler [1220704].
- Use ODNewRgn. [1220810]
- <21> 2/20/95 TÇ #1221861 BB: Incomplete AOCE support needs
- to be removed from OpenDoc
- <20> 1/31/95 RR # 1206909 Pass ev to
- RemoveUnregisteredIdlers
- <19> 1/25/95 jpa Include StdExts.xh [1206907]
- <18> 1/13/95 RR Replace calls to MouseEnter etc with calls
- to HandleEvent
- <17> 1/12/95 jpa Don't use obsolete Toolbox names [1211211].
- Change qd --> ODQDGlobals [1210936]
- <16> 1/9/95 NP 1194880: SemtIntf name changes.
- <15> 11/28/94 RR Prepare for thread support
- <14> 9/30/94 RR #1167950 Allow unregistering while idling.
- Call RemoveUnregisteredIdlers in
- HandleNULLEvent
- <13> 9/29/94 RA 1189812: Mods for 68K build.
- <12> 9/20/94 NP 1187682: Initial TSM support.
- <11> 9/20/94 RR #1154046 Moved ref counting into IdleList
- methods so that an unregistered part is not
- released. #1156594 Call
- WindowState->HandleAOCEMailerEvent instead
- of calling SMPMailerEvent directly.
- <10> 9/2/94 eeh #?: added SMPMailerEvent call to enable use
- of mailer until Richard and I agree on a
- cleaner fix to a bug in his hamper.
- <9> 8/31/94 TÇ #1183129, #1183116, #1183119, #1183111:
- Lots of ErrorCode cleanup.
- <8> 8/15/94 JBS 1181156: UI API Cleanup
- <7> 8/10/94 JBS 1179919: coordinate system bias changes
- <6> 8/4/94 eeh bug 1177981: add
- ODDispatcherGetDispatchModule
- <5> 7/27/94 eeh Changes necessitated by WinStat.idl changes
- <4> 7/26/94 eeh ODQDPoint->Point
- <3> 6/30/94 CG Moved InitStandardDispatchModule to
- InitDispatch from InitSession.
- <2> 9/27/94 RR Call InitBaseDispatcher
- <1> 9/26/94 RR first checked in
-
- To Do:
- * Get Gestalt bit for gestaltHasBGMouseDown.
- * Call SetBgndMouseHandler via PrivateInterfaceLib if it's exported therefrom.
- * Check whether bg mousedown handler calls are exported from PrivateInterfaceLib
- and use those if they are (for Copland compatibility)
-
- In Progress:
-
- */
-
-
- /*
- * This file was generated by the SOM Compiler.
- * Generated using:
- * SOM Emitter emitxtm.dll: somc/smmain.c
- */
-
- #define ODDispatcher_Class_Source
- #define VARIABLE_MACROS
- #include <Disptch.xih>
-
- #ifndef SOM_ODDispatchModule_xh
- #include "DispMod.xh"
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include "WinStat.xh"
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include "Window.xh"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include "ODSessn.xh"
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _IDLELIST_
- #include "IdleList.h"
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef _DISPTABL_
- #include "DispTabl.h"
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include "Facet.xh"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include "Frame.xh"
- #endif
-
- #ifndef SOM_ODPart_xh
- #include "Part.xh"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef SOM_ODStandardDispatchModule_xh
- #include <StdDisp.xh>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODSemanticInterface_xh
- #include <SemtIntB.xh>
- #endif
-
- #ifndef SOM_ODAppleEvent_xh
- #include <ODAplEvt.xh>
- #endif
-
- #ifndef _BARRAY_
- #include "BArray.h"
- #endif
-
- #ifndef _ODDESUTL_
- #include "ODDesUtl.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StandardExtensions_defined
- #include <StdExts.xh>
- #endif
-
- #ifndef _DSPUTILM_
- #include "DspUtilM.h"
- #endif
-
- #ifndef _BGCLICKM_
- #include "BGClickM.h"
- #endif
-
- #ifndef _ODTHREDM_
- #include "ODThredM.h"
- #endif
-
- #ifndef __TEXTSERVICES_
- #include "TextServices.h"
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #define ODLogEvents 0
-
- //------------------------------------------------------------------------------
- // ODDispatcher
- //------------------------------------------------------------------------------
-
- #pragma segment ODDispatcher
-
- #include "DisptchB.cpp" // Platform-independent methods, if any
-
- SOM_Scope void SOMLINK ODDispatcherRegisterIdle(ODDispatcher *somSelf, Environment *ev,
- ODPart* part,
- ODFrame* frame,
- ODIdleFrequency frequency)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherRegisterIdle");
-
- SOM_TRY
-
- if (part)
- _fIdleList->AddIdle(ev, part, frame, frequency);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODDispatcherUnregisterIdle(ODDispatcher *somSelf, Environment *ev,
- ODPart* part,
- ODFrame* frame)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherUnregisterIdle");
-
- SOM_TRY
-
- if (part)
- _fIdleList->RemoveIdle(ev, part, frame);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODDispatcherSetIdleFrequency(ODDispatcher *somSelf, Environment *ev,
- ODPart* part,
- ODFrame* frame,
- ODIdleFrequency frequency)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherSetIdleFrequency");
-
- SOM_TRY
-
- if (part)
- _fIdleList->SetIdleFrequency(ev, part, frame, frequency);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODDispatcherYield(ODDispatcher *somSelf, Environment *ev,
- ODFrame* frame)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherYield");
-
- SOM_TRY
-
- /*
- Will Call WaitNextEvent(), masking out all but null and update events.
- Idle events are sent to all but the part that yielded
- */
- const ODSLong kODSleepTicks = 20L;// Number sleep ticks
-
- EventRecord eventRec;
- WaitNextEvent ( updateMask, &eventRec, somSelf->GetSleepTime(ev), somSelf->GetMouseRegion(ev) ) ;
- if (eventRec.what == nullEvent)
- somSelf->HandleNullEvent(ev, (ODEventData*) &eventRec, frame); // Note Cast
- else
- somSelf->Dispatch(ev, (ODEventData*) &eventRec);
-
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODDispatcherSetMouseRegion(ODDispatcher *somSelf, Environment *ev,
- ODRgnHandle area)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherSetMouseRegion");
-
- if (area && _fPartMouseRegion)
- {
- CopyRgn(area, _fPartMouseRegion);
- }
-
- }
-
- SOM_Scope ODRgnHandle SOMLINK ODDispatcherGetMouseRegion(ODDispatcher *somSelf, Environment *ev)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherGetMouseRegion");
-
- SOM_TRY
-
- if (somSelf->MouseRegionIsInvalid(ev))
- somSelf->ComputeMouseRegion(ev);
-
-
- /*
-
- CGrafPort desktopPort; // Used for showing cursor region
- long ticks; // Used for showing cursor region
- GrafPtr savedPort; // Used for showing cursor region
-
- // Cursor region is in global coords. Need to create desktop port
- GetPort(&savedPort);
- OpenCPort(&desktopPort);
- CopyRgn(GetGrayRgn(), desktopPort.visRgn);
- desktopPort.portRect = (*(desktopPort.visRgn))->rgnBBox;
-
- PenNormal();
- PenMode(patXor);
-
- PaintRgn(_fPartMouseRegion);
- Delay(30, &ticks);
- PaintRgn(_fMouseRegion);
-
- CloseCPort(&desktopPort);
- SetPort(savedPort);
-
-
- */
-
- return _fMouseRegion;
-
- SOM_CATCH_ALL
-
- return kODNULL;
-
- SOM_ENDTRY
-
- return kODNULL;
- }
-
- SOM_Scope void SOMLINK ODDispatcherInvalidateFacetUnderMouse(ODDispatcher *somSelf, Environment *ev)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherInvalidateFacetUnderMouse");
-
- SOM_TRY
-
- _fFacetUnderMouse = kODNULL;
- somSelf->InvalidateMouseRegion(ev);
- SetCursor(&ODQDGlobals.arrow);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope ODSLong SOMLINK ODDispatcherGetSleepTime(ODDispatcher *somSelf, Environment *ev)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherGetSleepTime");
-
- SOM_TRY
-
- // Don't sleep at all if another thread is ready to run:
- if( ODAnyThreadsReady() )
- return 0;
-
- return _fIdleList->GetMinIdleFrequency();
-
- SOM_CATCH_ALL
-
- return 0;
-
- SOM_ENDTRY
-
- return 0;
- }
-
- static OSErr pascal HandleTSMEvents(const AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon)
- {
- ODSession* session = (ODSession*)handlerRefcon;
- Environment* ev = somGetGlobalEnvironment();
- // DescType eventID;
- // DescType actualType;
- Size maxSize = sizeof(DescType);
- // Size actualSize;
- OSErr result = noErr;
- ODSemanticInterface* semtIntf = kODNULL; ODVolatile(semtIntf);
- ODPart* keyPart = kODNULL; ODVolatile(keyPart);
-
- TRY
- TempODFrame keyFrame
- = session->GetArbitrator(ev)->AcquireFocusOwner(ev,
- session->Tokenize(ev,
- kODKeyFocus));
- // -- TÇ tempobj'd
- if ((ODFrame*)keyFrame != kODNULL)
- {
- keyPart = keyFrame->AcquirePart(ev);
- if (keyPart->HasExtension(ev, kODExtSemanticInterface))
- {
- semtIntf = (ODSemanticInterface*)keyPart->AcquireExtension(ev,
- kODExtSemanticInterface);
- // WHAT WAS I GOING TO DO WITH THIS INFO? - NP 6/21/95
- // result = AEGetAttributePtr(theAppleEvent, keyEventIDAttr,
- // typeType, &actualType,
- // (Ptr)&eventID, maxSize,
- // &actualSize);
- // if (result || actualType != typeType || actualSize != maxSize)
- // THROW(errAEEventNotHandled);
-
- // CREATE NEW ODAPPLEEVENTS FOR THE PARAMETERS
- ODAppleEvent* odEvent = new ODAppleEvent;
- THROW_IF_NULL(odEvent);
- odEvent->InitODAppleEvent(ev);
- AEDescToODDesc((AEDesc*)theAppleEvent, odEvent);
- ODAppleEvent* odReply = new ODAppleEvent;
- THROW_IF_NULL(odReply);
- odReply->InitODAppleEvent(ev);
- AEDescToODDesc((AEDesc*)reply, odReply);
-
- // PASS THE EVENT TO THE PART
- TRY
- semtIntf->CallEventHandler(ev, keyPart, odEvent, odReply);
- CATCH_ALL
- result = ErrorCode();
- ENDTRY
-
- // CLEAN UP. NOTE, WE MUST UPDATE THE REPLY DATAHANDLE SO THAT
- // THE APPLE EVENTS MANAGER SEES THE CHANGE (IF ANY).
- delete odEvent;
- if (reply->descriptorType != typeNull
- && reply->dataHandle != kODNULL
- && !result)
- {
- ODByteArray data = odReply->GetRawData(ev);
- SetHandleSize(reply->dataHandle, data._length);
- THROW_IF_ERROR(MemError());
- ODBlockMove(data._buffer, *(reply->dataHandle),
- data._length);
- DisposeByteArrayStruct(data);
- }
- delete odReply;
- }
- else
- result = errAEEventNotHandled;
- }
- else
- result = errAEEventNotHandled;
- CATCH_ALL
- result = ErrorCode();
- ENDTRY
-
- if ( semtIntf != kODNULL )
- semtIntf->Release(ev);
- if ( keyPart != kODNULL )
- keyPart->Release(ev);
-
- return result;
- }
-
- SOM_Scope void SOMLINK ODDispatcherInitDispatcher(ODDispatcher *somSelf, Environment *ev,
- ODSession* session)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherInitDispatcher");
-
- const Boolean kIsSysHandler = kODTrue;
-
- SOM_TRY
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fExit = kODFalse;
- _fDispatchTable = kODNULL;
- _fSession = kODNULL;
- _fIdleList = kODNULL;
-
- _fMouseRegion = kODNULL;
- _fPartMouseRegion = kODNULL;
- _fFacetUnderMouse = kODNULL;
- */
-
- somSelf->InitObject(ev);
-
- _fSession = session;
-
- _fDispatchTable = new DispatchTable;
- THROW_IF_NULL(_fDispatchTable);
-
- _fIdleList = new IdleList;
- THROW_IF_NULL(_fIdleList);
-
- _fMouseRegion = ODNewRgn();
-
- _fPartMouseRegion = ODNewRgn();
-
- ODStandardDispatchModule* stdModule = kODNULL;
-
- stdModule = new ODStandardDispatchModule();
- THROW_IF_NULL(stdModule);
- stdModule->InitStandardDispatchModule(ev,session);
-
- somSelf->AddDispatchModule(ev,mouseDown, stdModule);
-
- somSelf->AddDispatchModule(ev,mouseUp, stdModule);
- somSelf->AddDispatchModule(ev,keyDown, stdModule);
- somSelf->AddDispatchModule(ev,keyUp, stdModule);
- somSelf->AddDispatchModule(ev,autoKey, stdModule);
- somSelf->AddDispatchModule(ev,updateEvt, stdModule);
- somSelf->AddDispatchModule(ev,diskEvt, stdModule);
- somSelf->AddDispatchModule(ev,activateEvt,stdModule);
- somSelf->AddDispatchModule(ev,osEvt, stdModule);
- somSelf->AddDispatchModule(ev,kHighLevelEvent, stdModule);
- somSelf->AddDispatchModule(ev,kODEvtMenu, stdModule);
- somSelf->AddDispatchModule(ev,kODEvtBGMouseDown, stdModule);
- somSelf->AddDispatchModule(ev,kODEvtMouseDownBorder, stdModule);
- somSelf->AddDispatchModule(ev,kODEvtMouseDownEmbedded, stdModule);
- somSelf->AddDispatchModule(ev,kODEvtBGMouseDownEmbedded, stdModule);
- somSelf->AddDispatchModule(ev,kODEvtMouseUpEmbedded, stdModule);
-
- // TSM support
- AEEventHandlerUPP proc = NewAEEventHandlerProc(HandleTSMEvents);
- THROW_IF_ERROR(AEInstallEventHandler(kTextServiceClass,
- kUpdateActiveInputArea,
- proc,
- (long)_fSession,
- !kIsSysHandler));
- THROW_IF_ERROR(AEInstallEventHandler(kTextServiceClass, kPos2Offset,
- proc,
- (long)_fSession,
- !kIsSysHandler));
- THROW_IF_ERROR(AEInstallEventHandler(kTextServiceClass, kOffset2Pos,
- proc,
- (long)_fSession,
- !kIsSysHandler));
- THROW_IF_ERROR(AEInstallEventHandler(kTextServiceClass,
- kShowHideInputWindow,
- proc,
- (long)_fSession,
- !kIsSysHandler));
-
- // Background mouse-down support:
- ODInstallBGMouseDownHandler(session);
-
- // Thread support:
- ODInitThreads();
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODDispatcherInvalidateMouseRegion(ODDispatcher *somSelf, Environment *ev)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherInvalidateMouseRegion");
-
- SOM_TRY
-
- ASSERT(_fPartMouseRegion != kODNULL, kODErrDispatcherNotInitialized);
- SetEmptyRgn(_fPartMouseRegion);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope ODFacet* SOMLINK ODDispatcherGetFacetUnderMouse(ODDispatcher *somSelf, Environment *ev)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherGetFacetUnderMouse");
-
- return _fFacetUnderMouse;
- }
-
- SOM_Scope void SOMLINK ODDispatcherSetFacetUnderMouse(ODDispatcher *somSelf, Environment *ev,
- ODFacet* facet)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherSetFacetUnderMouse");
-
-
- _fFacetUnderMouse = facet;
-
- }
-
- SOM_Scope ODBoolean SOMLINK ODDispatcherHandleNullEvent(ODDispatcher *somSelf, Environment *ev,
- ODEventData* event,
- ODFrame* skipFrame)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherHandleNullEvent");
-
- ODBoolean handled = kODFalse;
-
- SOM_TRY
-
- // Give threads time to run:
- ODYield();
-
- IdleListIterator iter(_fIdleList);
- ODFrame* frame = kODNULL;
- ODTicks now = TickCount();
-
- for (IdleInfo* idleInfo = iter.First(); iter.IsNotComplete(); idleInfo = iter.Next())
- {
- if ( (idleInfo->NeedsIdle( now )))
- {
- frame = idleInfo->GetFrame();
- if ( (frame == kODNULL) || !ODObjectsAreEqual(ev, frame,skipFrame) )
- {
- TRY{
- idleInfo->GetPart()->HandleEvent(ev,event, frame, kODNULL, kODNULL);
- }CATCH_ALL{
- // ignore exception
- }ENDTRY
- idleInfo->SetLastIdle( now );
- }
- }
- }
- handled = kODTrue;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return handled;
- }
-
- SOM_Scope ODBoolean SOMLINK ODDispatcherMouseRegionIsInvalid(ODDispatcher *somSelf, Environment *ev)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherMouseRegionIsInvalid");
-
- ODBoolean isInvalid = kODTrue;
-
- if (Button())
- return kODFalse;
-
- SOM_TRY
-
- ASSERT(_fPartMouseRegion != kODNULL, kODErrDispatcherNotInitialized);
- isInvalid = EmptyRgn(_fPartMouseRegion);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return isInvalid;
- }
-
- SOM_Scope void SOMLINK ODDispatcherComputeMouseRegion(ODDispatcher *somSelf, Environment *ev)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherComputeMouseRegion");
-
- SOM_TRY
-
- somSelf->CheckFacetUnderMouse(ev); // A Part may call SetMouseRegion
- /*
- if no frame is under the mouse, compute an appropriate big region
- either way, add the current mouse location?
- And clip region to frame shape?
- */
-
- // Add the current mouse location to whatever region is computed by the part
- Point globalMouse;
- GetMouse(&globalMouse);
- LocalToGlobal(&globalMouse);
-
- SetRectRgn(_fMouseRegion, globalMouse.h, globalMouse.v, globalMouse.h + 1, globalMouse.v + 1);
- UnionRgn(_fPartMouseRegion, _fMouseRegion, _fPartMouseRegion);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- // <eeh> note: this code is a slightly modified version of IsThisKeyDown found
- // in ODDebug.cpp. I'm using this instead because 1) I'm not sure it's available
- // when ODDebug isn't defined; and 2) because this calls GetKeys only once instead
- // of four times as would be necessary were IsThisKeyDown to be used.
-
- inline Boolean OneDown( unsigned char keyMap[], ODUShort key )
- { return ((keyMap[key >> 3] >> (key & 7)) & 1); }
-
- ODBoolean IsThisKeyDown(ODUShort theKey);
- static ODSShort Modifiers()
- {
- unsigned char theKeys[16];
- GetKeys((UInt32*)&theKeys);
-
- ODSShort mods = 0;
- // the index into the key map is the virtual keycode - 1....
- if (OneDown(theKeys, 0x0038))
- mods |= shiftKey;
- if (OneDown(theKeys, 0x003A))
- mods |= optionKey;
- if (OneDown(theKeys, 0x003B))
- mods |= controlKey;
- if (OneDown(theKeys, 0x0037))
- mods |= cmdKey;
- return mods;
- }
-
- SOM_Scope void SOMLINK ODDispatcherCheckFacetUnderMouse(ODDispatcher *somSelf, Environment *ev)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherCheckFacetUnderMouse");
-
- SOM_TRY
-
- Point globalPoint;
- ODPoint windowPoint;
-
- GetMouse(&globalPoint);
- LocalToGlobal(&globalPoint);
-
- if (!SetTSMCursor(globalPoint)) // NP: temporary. dispatcher really needs
- // to set a 1-pixel mouse region so that
- // SetTSMCursor can be called every time
- // the mouse moves.
- {
- ODWindow* odWindow = kODNULL;
- ODFacet* foundFacet = kODNULL;
-
- ODWindowState* _fWindowState = _fSession->GetWindowState(ev); // temp
-
- TempODFrame mouseFocusFrame = kODNULL;
- mouseFocusFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fSession->Tokenize(ev,kODMouseFocus));
-
- if (mouseFocusFrame)
- {
-
- if (_fFacetUnderMouse && ODObjectsAreEqual(ev, mouseFocusFrame, _fFacetUnderMouse->GetFrame(ev)))
- {
- odWindow = _fFacetUnderMouse->GetWindow(ev);
- odWindow->GetWindowPoint(ev, &globalPoint, &windowPoint);
-
- ODEventData event;
- SetEvent(event,kODEvtMouseWithin, globalPoint, Modifiers() );
- ODEventInfo info;
- SetEventInfo(info, windowPoint);
- WindowToLocal(ev, info.where, _fFacetUnderMouse);
-
- TempODPart part = mouseFocusFrame->AcquirePart(ev);
- #if ODDebug && ODLogEvents
- LogEvent(&event, &info, mouseFocusFrame, _fFacetUnderMouse);
- #endif
- part->HandleEvent(ev, &event, mouseFocusFrame, _fFacetUnderMouse, &info);
- }
- return;
- }
-
- odWindow = _fWindowState->FindODWindow(ev, &globalPoint);
-
- if (odWindow)
- {
- TempODWindow tempWindow = odWindow; // ensure it's released
- odWindow->GetWindowPoint(ev, &globalPoint, &windowPoint);
- TempODFrame activeFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fSession->Tokenize(ev,kODSelectionFocus));
- ODFacet* activeFacet = activeFrame ? GetActiveFacetWithBorderUnderPoint(ev, activeFrame, odWindow, windowPoint) : kODNULL;
-
- if (activeFacet)
- foundFacet = activeFacet->GetContainingFacet(ev);
- else
- {
- foundFacet = odWindow->GetFacetUnderPoint(ev, &windowPoint);
- if (foundFacet && (foundFacet->GetFrame(ev)->IsFrozen(ev) || foundFacet->IsSelected(ev)))
- foundFacet = foundFacet->GetContainingFacet(ev);
- }
- }
-
-
- if (ODObjectsAreEqual(ev, foundFacet, _fFacetUnderMouse))
- {
- if (foundFacet)
- {
- ODEventData event;
- SetEvent(event,kODEvtMouseWithin, globalPoint, Modifiers());
- ODEventInfo info;
- SetEventInfo(info, windowPoint);
- WindowToLocal(ev, info.where, _fFacetUnderMouse);
-
- ODFrame* frame = _fFacetUnderMouse->GetFrame(ev);
- #if ODDebug && ODLogEvents
- LogEvent(&event, &info, frame, _fFacetUnderMouse);
- #endif
- TempODPart part = frame->AcquirePart(ev);
- part->HandleEvent(ev, &event, frame, _fFacetUnderMouse, &info);
- }
- }
- else
- {
- if (_fFacetUnderMouse)
- {
- ODEventData event;
- SetEvent(event,kODEvtMouseLeave, globalPoint, Modifiers());
- ODEventInfo info;
- SetEventInfo(info, windowPoint);
- WindowToLocal(ev, info.where, _fFacetUnderMouse);
-
- ODFrame* frame = _fFacetUnderMouse->GetFrame(ev);
- #if ODDebug && ODLogEvents
- LogEvent(&event, &info, frame, _fFacetUnderMouse);
- #endif
- TempODPart part = frame->AcquirePart(ev);
- part->HandleEvent(ev, &event, frame, _fFacetUnderMouse, &info);
- }
- if (foundFacet)
- {
- ODEventData event;
- SetEvent(event,kODEvtMouseEnter, globalPoint, Modifiers());
- ODEventInfo info;
- SetEventInfo(info, windowPoint);
- WindowToLocal(ev, info.where, foundFacet);
-
- ODFrame* frame = foundFacet->GetFrame(ev);
- #if ODDebug && ODLogEvents
- LogEvent(&event, &info, frame, foundFacet);
- #endif
- TempODPart part = frame->AcquirePart(ev);
- part->HandleEvent(ev, &event,frame,foundFacet, &info);
- }
- _fFacetUnderMouse = foundFacet;
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODDispatchersomUninit(ODDispatcher *somSelf)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatchersomUninit");
-
- ODDeleteObject(_fDispatchTable);
- ODDeleteObject(_fIdleList);
- ODDisposeHandle((Handle)_fMouseRegion);
- ODDisposeHandle((Handle)_fPartMouseRegion);
-
- parent_somUninit(somSelf);
- }
-
- SOM_Scope ODSize SOMLINK ODDispatcherPurge(ODDispatcher *somSelf, Environment *ev,
- ODSize size)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherPurge");
-
- ODUnused(size);
- return 0;
- }
-
- SOM_Scope void SOMLINK ODDispatcherAddDispatchModule(ODDispatcher *somSelf, Environment *ev,
- ODEventType eventType,
- ODDispatchModule* dispatchModule)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherAddDispatchModule");
-
- SOM_TRY
-
- ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
-
- if (dispatchModule)
- {
- _fDispatchTable->AddDispatchModule(eventType,dispatchModule);
- }
- else
- THROW(kODErrIllegalNullDispatchModuleInput);
-
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope ODDispatchModule* SOMLINK ODDispatcherGetDispatchModule(ODDispatcher *somSelf, Environment *ev,
- ODEventType eventType)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherGetDispatchModule");
-
- ODDispatchModule* module = kODNULL;
-
- SOM_TRY
-
- ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
-
- module = _fDispatchTable->GetDispatchModule( eventType );
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return module;
- }
-
- SOM_Scope void SOMLINK ODDispatcherRemoveDispatchModule(ODDispatcher *somSelf, Environment *ev,
- ODEventType eventType)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherRemoveDispatchModule");
-
- SOM_TRY
-
- ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
-
- _fDispatchTable->RemoveDispatchModule(eventType);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODDispatcherAddMonitor(ODDispatcher *somSelf, Environment *ev,
- ODEventType eventType,
- ODDispatchModule* dispatchModule)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherAddMonitor");
-
- SOM_TRY
-
- ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
-
- if (dispatchModule)
- _fDispatchTable->AddMonitor(eventType,dispatchModule);
- else
- THROW(kODErrIllegalNullDispatchModuleInput);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope void SOMLINK ODDispatcherRemoveMonitor(ODDispatcher *somSelf, Environment *ev,
- ODEventType eventType,
- ODDispatchModule* dispatchModule)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherRemoveMonitor");
-
- SOM_TRY
-
- ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
-
- _fDispatchTable->RemoveMonitor(eventType, dispatchModule);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- static Boolean IntlTSMEvent(EventRecord *event) // NP: from TE 27.
- {
- short oldFont;
- ScriptCode keyboardScript;
-
- // make sure we have a port and it's not the Window Manager port
- if (ODQDGlobals.thePort != nil && FrontWindow() != nil)
- {
- oldFont = ODQDGlobals.thePort->txFont;
- keyboardScript = GetScriptManagerVariable(smKeyScript);
- if (FontToScript(oldFont) != keyboardScript)
- TextFont(GetScriptVariable(keyboardScript, smScriptAppFond));
- };
- return TSMEvent(event);
- }
-
- SOM_Scope ODBoolean SOMLINK ODDispatcherDispatch(ODDispatcher *somSelf, Environment *ev,
- ODEventData* eventData)
- {
- ODBoolean handled = kODFalse;
-
- SOM_TRY
-
- ODEventInfo eventInfo; // Note: Need some utility functions
- eventInfo.embeddedFrame = kODNULL;
- eventInfo.embeddedFacet = kODNULL;
- ODPoint zero(0,0);
- eventInfo.where = zero;
- eventInfo.propagated = kODFalse;
-
- handled =somSelf->Redispatch(ev, eventData, &eventInfo);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return handled;
- }
-
- SOM_Scope ODBoolean SOMLINK ODDispatcherRedispatch(ODDispatcher *somSelf, Environment *ev,
- ODEventData* eventData,
- ODEventInfo* eventInfo)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherDispatch");
-
- ODBoolean handled = kODFalse;
- ODEventType eventType = eventData->what;
-
- SOM_TRY
-
- ASSERT(_fDispatchTable != kODNULL,kODErrDispatcherNotInitialized);
-
- {
- OrderedCollection* monitors = kODNULL;
- ODDispatchModule* module = kODNULL;
-
- monitors = _fDispatchTable->GetMonitors(eventType);
- if (monitors)
- {
- OrderedCollectionIterator iter(monitors);
-
- for (module = (ODDispatchModule*) iter.First();
- iter.IsNotComplete();
- module = (ODDispatchModule*) iter.Next())
- {
- module->Dispatch(ev, eventData, eventInfo);
- }
- }
-
- if (!TSMEvent((EventRecord*)eventData))
- {
- module = _fDispatchTable->GetDispatchModule(eventType);
- if (module)
- handled = module->Dispatch(ev, eventData, eventInfo);
- }
- }
- // Moved to the end so that dispatch modules can monitor or patch
- // null event handling
- if ((eventType == nullEvent) && !handled)
- {
- somSelf->HandleNullEvent(ev,eventData, kODNULL);
- handled = kODTrue;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return handled;
- }
-
- SOM_Scope void SOMLINK ODDispatcherExit(ODDispatcher *somSelf, Environment *ev)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherExit");
-
- _fExit = kODTrue;
- }
-
- SOM_Scope ODBoolean SOMLINK ODDispatcherShouldExit(ODDispatcher *somSelf, Environment *ev)
- {
- ODDispatcherData *somThis = ODDispatcherGetData(somSelf);
- ODDispatcherMethodDebug("ODDispatcher","ODDispatcherShouldExit");
-
- return _fExit;
- }
-